package pages;

import core.TestBase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import utils.Log4Test;
import org.openqa.selenium.StaleElementReferenceException;
import java.util.List;

/**
 * Created by 1 on 07.07.2014.
 */
public class NotebooksPage extends TestBase {

    protected By searchTitle = By.tagName("h1");
    protected By activeTab = By.xpath(".//*[@id='computers-notebooks']/div");

    List<WebElement> listOfManufactures;

    protected WebElement searchElem1;
    protected WebElement searchElem2;
    protected WebElement searchElem3;

    public String verifyPageName() {

        Log4Test.info("Verify page name");

        searchElem1 = webDriver.findElement(searchTitle);

        return searchElem1.getText();
    }

    public String verifyIsActiveTab() {
        Log4Test.info("Verify if tab is active");
        searchElem2 = webDriver.findElement(activeTab);
        return searchElem2.getAttribute("class");
    }

    public int verifyManufacturesQuantity() {
        Log4Test.info("manufactures quantity");
        int count = 0;
        listOfManufactures = webDriver.findElements(By.xpath(".//ul/li[2]/ul/li/a"));

        for (WebElement e : listOfManufactures) count++;
        return count;
    }

    public void clickApple() {

        for (WebElement e : listOfManufactures) {
            if (e.getText().contains("Apple")) {

                e.click();
                break;
            }
        }

    }
}
